var http=require("http");
var data = [];
var fs = require("fs");
var server=http.createServer(function(req,res){
        if(req.url.startsWith("/login?")){
		res.setHeader("Content-Type","text-html");
		if(req.url.indexOf("?")>-1){	
			var str = req.url.split("?");
			str = str[1];
			var arr = str.split("&");
        		var one = {};
       			arr.forEach(function(o){
                	var s = o.split("=");
                	one[s[0]]=s[1];
        		});
        		data.push(one);
        		console.log(data);
			if(one.name == "root"&&one.pass == "123"){
				res.end("你好，超级管理员。");
			}
			else if(one.name == "yu"&&one.pass == "123")
			{
				res.end("登录成功");
			}
			else
			{	    
				fs.readFile("test2.html",function(err,data){
					res.end(data);			
				});
			}
		}
	}else if(req.url.startsWith("/reg")){
			fs.readFile("reg.html",function(err,data){
				res.end(data);
			});	
	}
});
server.listen(3000);

